/**
 * Created by Freeman on 2017/3/20.
 */
import * as types from '../types'
import * as constants from '../../AppConstants'
import utils from '../../commons/utils'

class Header {
  constructor(header) {
    // æ˜¯å¦æ˜¾ç¤ºheader
    this.isShow = (header && header['isShow']) ? header['isShow'] : true
    //æ˜¯å¦æ˜¾ç¤ºå³ä¾§æ–‡å­—
    this.isRightTxt = (header && header['isRightTxt']) ? header['isRightTxt'] : false
    //å³ä¾§æ˜¾ç¤ºæ–‡å­—
    this.rightTxt = (header && header['rightTxt']) ? header['rightTxt'] : ''
    // å³ä¾§äº‹ä»¶
    this.rightEvent = (header && header['rightEvent']) ? header['rightEvent'] : null
    //å·¦ä¾§äº‹ä»¶
    this.leftEvent = (header && header['leftEvent']) ? header['leftEvent'] : null
    //å·¦ä¾§ç®­å¤´äº‹ä»¶
    this.backEvent = (header && header['backEvent']) ? header['backEvent'] : false
    //æ˜¯å¦æ˜¾ç¤ºæœç´¢æŒ‰é’®
    this.isSeach = (header && header['isSeach']) ? header['isSeach'] : false
    //æ˜¯å¦æ˜¾ç¤ºæ”¶è—æŒ‰é’®
    this.isLove = (header && header['isLove']) ? header['isLove'] : false
    //æ˜¯å¦æ˜¾ç¤ºå‘å¸ƒæŒ‰é’®
    this.isPublish = (header && header['isPublish']) ? header['isPublish'] : false
    //æ˜¯å¦æ˜¾ç¤ºæ›´å¤šæŒ‰é’®
    this.isMore = (header && header['isMore']) ? header['isMore'] : false
    // æ›´å¤šæŒ‰é’®ç‚¹å‡»äº‹ä»¶
    this.moreEvent = (header && header['moreEvent']) ? header['moreEvent'] : false
    // è½¬è®©æŒ‰é’®äº‹ä»¶
    this.transferEvent = (header && header['transferEvent']) ? header['transferEvent'] : null
    //æ˜¯å¦æ˜¾ç¤ºè¿”å›žæŒ‰é’®
    this.isShowBack = (header && header['isShowBack']) ? header['isShowBack'] : false
    //æ˜¯å¦æ˜¾ç¤ºå·¦ä¾§æ–‡å­—
    this.isLeftTxt = (header && header['isLeftTxt']) ? header['isLeftTxt'] : false
    //å·¦ä¾§æ˜¾ç¤ºæ–‡å­—
    this.leftTxt = (header && header['leftTxt']) ? header['leftTxt'] : ''
    //æ ‡é¢˜æ–‡å­—
    this.title = (header && header['title']) ? header['title'] : ''
    //æ˜¯å¦æ˜¾ç¤ºåˆ‡æ¢ç­çº§
    this.isGrade = (header && header['isGrade']) ? header['isGrade'] : false
    //æ˜¯å¦æ˜¾ç¤ºç­çº§å°ä¸‰è§’
    this.isArrow = (header && header['isArrow']) ? header['isArrow'] : false
    //加入的所有班级
    this.joinGrades = (header && header['joinGrades']) ? header['joinGrades'] : []
    //是否收藏
    this.isFavorite = (header && header['isFavorite']) ? header['isFavorite'] : false
  }
}


// initial state
const state = {
  header: new Header(),
  draft: new Header({           // 草稿箱组件Header
    isRightTxt: true,
    isLeftTxt: true,
    rightTxt: '发送',
    leftTxt: '取消',
  }),
  noneJoin: new Header({
    title: '当前未创建/加入任何班级'
  })
}

// getters
const getters = {
  header: (state) => {
    return new Header()
  },
  backHeader: (state) => {
    let header = new Header()
    header.isShowBack = true
    return header
  }
}

// mutations
const mutations = {
  [types.UPDATE_HEADER](state, header) {
    Object.assign(state.header, header);
  }
}

// actions
const actions = {}

export default {
  state,
  getters,
  actions,
  mutations
}
